package cn.htu.edu.payload.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Data
public class PageRequest {
    @ApiModelProperty(value = "pageNo 页数 从1开始", example = "1", required = true)
    @NotNull(message = "pageNo")
    @Min(value = 1, message = "pageNo 不能小于1")
    private Integer pageNo = 1;

    @ApiModelProperty(value = "pageSize 条数", example = "10", required = true)
    @NotNull(message = "pageSize")
    @Min(value = 1, message = "pageSize 不能小于1")
    private Integer pageSize = 5;

    public static Page getPage(PageRequest request) {
        return new Page(request.getPageNo(), request.getPageSize());
    }

    public static Page getPage(PageRequest request, Integer total) {
        return new Page(request.getPageNo(), request.getPageSize()).setSearchCount(false).setTotal(total);
    }
}
